package demo1;

public class Test5 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("t1执行中");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        System.out.println("main等待t1");
        t1.join(3000);  // 最多等你三秒
        System.out.println("main结束等待");
        for (int i = 0; i < 5; i++) {
            System.out.println("main主线程");
             Thread.sleep(1000);
        }
    }
}
